<?php

namespace Admin\Controller;

/**
 * 
 * 文件用途描述: 银行卡图标管理
 * @authors xiaohui
 * @date    2017-09-27 17:44:01
 */
class BankIconController extends CommonController {
    
    /**
     * [index]
     * 函数用途描述: 列表
     * @date:  2017-09-27
     * @author: xiaohui
     * @param: [variable]
     * @return [type]     [description]
     */
    public function index() {

        $params = array(
            'showpage' => 10
        );
        $redata = D('BankIcon')->listData($params);
        $this->assign('list',$redata['list']);
        $this->assign('page',$redata['page']);
        $this->display();
    }

    /**
     * [add]
     * 函数用途描述: 添加
     * @date:  2017-09-27
     * @author: xiaohui
     * @param: [variable]
     */
    public function add() {

        if (IS_POST) {
            $data = I('post.');
            unset($data['id']);

            $result = D('BankIcon')->addData($data);

            if ($result) {
                $this->success('添加成功',U('index'));
            } else {
                $this->error('添加失败');
            }
        }
        $this->display('save');
    }

    /**
     * [edit]
     * 函数用途描述: 编辑
     * @date:  2017-09-27
     * @author: xiaohui
     * @param: [variable]
     * @return [type]     [description]
     */
    public function edit() {
        $id = I('get.id');
        
        if (IS_POST) {
            $data = I('post.');
            $data['time'] = time();

            if (empty($data['id'])) $this->error('没有修改的对象');
            
            $map['id'] = array('eq', $data['id']);

            $result = D('BankIcon')->editData($map, $data);

            if ($result) {
                $this->success('修改成功',U('index'));
            } else {
                $this->error('修改失败');
            }
        }

        $map['id'] = array('eq', $id);
        $result = D('BankIcon')->infoData($map);
        $this->assign('list', $result);
        $this->display('save');
    }

    /**
     * [del]
     * 函数用途描述: 删除
     * @date:  2017-09-27
     * @author: xiaohui
     * @param: [variable]
     * @return [type]     [description]
     */
    public function del() {
        $ids = I('post.id');

        if (empty($ids)) $this->error('请选择要删除的对象');

        $map['id'] = array('in', $ids);

        $result = D('BankIcon')->deleteData($map);
        
        if ($result) {
            $this->success('删除成功',U('index'));
        } else {
            $this->error('请先删除子菜单');
        }
    }

}